OLEObject Class
Used to automate COM servers. Use the WordApplication, ExcelApplication, and PowerPointApplication classes to automate Microsoft Office applications.
More information available in parent classes: Object
Constructors
Name | Parameters | Description |
OLEObject | ProgramID as String | ProgramID is the COM server's program ID as stored in the registry. It can also be the Class ID (in curly braces). This constructor will try to find a previous instance of the COM server if it's running. Otherwise, it will create a new instance. |
OLEObject | ProgramID as String NewInstance as Boolean | The ProgramID parameter is the same as above. The second parameter specifies whether to create a new instance of the COM server ( True) or try to use an existing one if it is running ( False). |
Notes
By default, OLEObject will make the property assignment by value. If it encounters an error it will try by reference if the property is an object. If the optional ByValue parameter is True, the property assignment is by value (i.e., a copy); otherwise the assignment is by reference (i.e., a pointer copy). In Visual Basic, an assignment by reference is done using the Set command, but since REALbasic doesn't provide that feature, you will need to use the ByValue parameter when you know the assignment should be by reference.
Currency types are treated as String to preserve precision.
Example
The following example automates Internet Explorer.
Dim v as Variant
Dim params(1) as Variant
obj = New OLEObject("InternetExplorer.Application", True)
obj.property("Visible") = True
params(1) = "http://www.realsoftware.com/"
v = obj.invoke("Navigate", params)
Exception err as OLEException
MsgBox err.message
The OLEObject class supports setting indexed properties. For example the Word.Document.Compatibility property is an indexed property. Here is an example.
Dim doc As OLEObject
word.Visible = True
doc = word.Documents.Add
Dim params(1) As Variant
params(1) = Office.wdNoTabHangIndent
doc.Value("Compatibility", params) = True
// or
/doc.Compatibility(Office.wdNoTabHangIndent)= True
This example automates Microsoft Word.
Dim docs as OLEObject
Dim doc as OLEObject
Dim range as OLEObject
Dim v as Variant
obj = New OLEObject("Word.Application", True)
// make it visible
obj.Property("Visible") = True
v = obj.Property("Documents")
if v.objectvalue IsA OLEObject then
docs = OLEObject(v.objectValue)
v = docs.invoke("Add")
if v.objectValue isa oleobject then
doc = OLEObject(v.objectValue)
v = doc.invoke("Range")
if v.objectValue IsA OLEObject then
range = OLEObject(v.objectValue)
range.Property("Text") = "This is a sentence."
end if
end if
end if
Exception err as OLEException
MsgBox err.message
See Also
ExcelApplication, Office, OLEContainer, OLEParameter, PowerPointApplication, WordApplication classes; OLEException error.